package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * <一句话功能简述>
 * <功能详细描述>
 *
 * @author  wKF63324
 * @version  [版本号, 2012-10-30]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class MyUtils
{
    private static String url = "jdbc:oracle:thin:@localhost:1521:XE";

    private static String user = "scott";

    private static String password = "tiger";

    private static Connection connection;

    /**
     * <一句话功能简述>
     * <功能详细描述>
     * @return connection
     * @see [类、类#方法、类#成员]
     */
    public static Connection getConnection()
    {
        try
        {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            connection = DriverManager.getConnection(url, user, password);
        }
        catch (ClassNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (SQLException e)
        {
            e.printStackTrace();
        }
        return connection;
    }

    static void free(ResultSet resultSet, Statement statement, Connection connections)
    {
        try
        {
            if (resultSet != null)
            {
                resultSet.close();
            }
        }
        catch (SQLException e)
        {
//            System.out.println("ResutSet�ر�ʧ��...");
            e.printStackTrace();
        }
        finally
        {
            try
            {
                if (statement != null)
                {
                    statement.close();
                }
            }
            catch (SQLException e)
            {
                e.printStackTrace();
//                System.out.println("Statement�ر�ʧ��...");
            }
            finally
            {
                try
                {
                    if (connection != null)
                    {
                        connection.close();
                    }
                }
                catch (SQLException e)
                {
                    e.printStackTrace();
//                    System.out.println("Connection�ر�ʧ��...");
                }
            }

        }
    }
}
